﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Collections;
using System.Text;
using System.Windows.Forms;
using System.Globalization;
using System.Threading;
using HotelSoft.HotelManagement_DTO;
using HotelSoft.HotelManagement_BUS;

namespace HotelSoft.HotelManagement_GUI
{
    public partial class frmTraCuu_NhanVien : Form
    {
        // Define the CS_DROPSHADOW constant
        private const int CS_DROPSHADOW = 0x00020000;

        // Override the CreateParams property
        protected override CreateParams CreateParams
        {
            get
            {
                CreateParams cp = base.CreateParams;
                cp.ClassStyle |= CS_DROPSHADOW;
                return cp;
            }
        }

        Double temp = 1;
        ArrayList dsNhanVien;
        NhanVienBUS busNhanVien = new NhanVienBUS();
        public frmTraCuu_NhanVien()
        {
            InitializeComponent();
            ThamSo thamso = new ThamSo();
            Cbm_ChucVu.Items.Add(thamso.dsCacLoaiNhanVien[0].ToString());
            Cbm_ChucVu.Items.Add(thamso.dsCacLoaiNhanVien[1].ToString());
            Cbm_ChucVu.Items.Add(thamso.dsCacLoaiNhanVien[2].ToString());
            Cbm_ChucVu.Items.Add(thamso.dsCacLoaiNhanVien[3].ToString());
            Cbm_ChucVu.Items.Add(thamso.dsCacLoaiNhanVien[4].ToString());
            Cbm_ChucVu.Items.Add(thamso.dsCacLoaiNhanVien[5].ToString());
            Cbm_ChucVu.SelectedIndex = -1;
        }

        private void frmTraCuu_NhanVien_Load(object sender, EventArgs e)
        {
            CultureInfo culture = (CultureInfo)CultureInfo.CurrentCulture.Clone(); 
            culture.DateTimeFormat.ShortDatePattern = "dd/MM/yyyy"; 
            Thread.CurrentThread.CurrentCulture = culture;
            timer1.Enabled = true;
            LayDanhSachNhanVien();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            this.Opacity = this.Opacity + 0.1;
            if (this.Opacity == temp)
                timer1.Enabled = false;
        }

        private void LayDanhSachNhanVien()
        {
            busNhanVien = new NhanVienBUS();
            dsNhanVien = busNhanVien.LayDanhSachNhanVien();
            LoadListView(dsNhanVien);
            lblTongso.Text = lvNhanVien.Items.Count.ToString();
        }

        public void LoadListView(ArrayList dsNhanVien)
        {
            lvNhanVien.Items.Clear();
            ListViewItem item;
            NhanVienDTO dt;
            for (int i = 0; i < dsNhanVien.Count; i++)
            {
                dt = (NhanVienDTO)dsNhanVien[i];
                item = new ListViewItem();
                item.Text = (i+1).ToString();
                item.SubItems.Add(dt.MASONV);
                item.SubItems.Add(dt.HOTENNV);
                item.SubItems.Add(dt.NGAYSINH);
                item.SubItems.Add(dt.GIOITINH.ToString());
                item.SubItems.Add(dt.NGAYVL);
                item.SubItems.Add(dt.SDTNV);
                item.SubItems.Add(dt.MUCLUONG.ToString());
                item.SubItems.Add(dt.DIACHINV);
                item.SubItems.Add(dt.CHUCVU);
                lvNhanVien.Items.Add(item);
            }
            lblTongso.Text = lvNhanVien.Items.Count.ToString();
        }

        private void Btn_TraCuu_Click(object sender, EventArgs e)
        {
            NhanVienDTO dtoNhanVienCanTraCuu = new NhanVienDTO();

            if (txtMaNV.Text == "")
                dtoNhanVienCanTraCuu.MASONV = null;
            else
                dtoNhanVienCanTraCuu.MASONV = txtMaNV.Text;
            if (Txt_HoTen.Text == "")
                dtoNhanVienCanTraCuu.HOTENNV = null;
            else
                dtoNhanVienCanTraCuu.HOTENNV = Txt_HoTen.Text;
            if (dt_NgaySinh.Value == null)
                dtoNhanVienCanTraCuu.NGAYSINH = null;
            else
                dtoNhanVienCanTraCuu.NGAYSINH = dt_NgaySinh.Text;
            if (dt_NgayVL.Value == null)
                dtoNhanVienCanTraCuu.NGAYVL = null;
            else
                dtoNhanVienCanTraCuu.NGAYVL = dt_NgayVL.Text;
            if (Txt_DiaChi.Text == "")
                dtoNhanVienCanTraCuu.DIACHINV = null;
            else
                dtoNhanVienCanTraCuu.DIACHINV = Txt_DiaChi.Text;
            if (Txt_DienThoai.Text == "")
                dtoNhanVienCanTraCuu.SDTNV = null;
            else
                dtoNhanVienCanTraCuu.SDTNV = Txt_DienThoai.Text;
            if (Txt_MucLuong.Text == "")
                dtoNhanVienCanTraCuu.MUCLUONG = 0;
            else
                dtoNhanVienCanTraCuu.MUCLUONG = float.Parse(Txt_MucLuong.Text);
            if (Cbm_ChucVu.Text == "")
                dtoNhanVienCanTraCuu.CHUCVU = null;
            else
                dtoNhanVienCanTraCuu.CHUCVU = Cbm_ChucVu.Text;

            dtoNhanVienCanTraCuu.GIOITINH = null;

            ArrayList dsTraCuuDuoc = busNhanVien.TraCuuNhanVien(dsNhanVien, dtoNhanVienCanTraCuu);
            LoadListView(dsTraCuuDuoc);
            if (lvNhanVien.Items.Count == 0)
                MessageBox.Show("Không tìm thấy thông tin của Nhân viên này!","Thông báo tra cứu");
            LamMoi();
        }

        private void Edit_Click(object sender, EventArgs e)
        {
            frmQuanly_NHANVIEN frm = new frmQuanly_NHANVIEN();
            frm.MANHANVIEN = lvNhanVien.FocusedItem.SubItems[1].Text;
            frm.ShowDialog();
        }

        private void lvNhanVien_MouseHover(object sender, EventArgs e)
        {
            balloonTip1.DefaultBalloonWidth = 100;
            balloonTip1.SetBalloonText(lvNhanVien, "Hãy bấm chuột phải để thực hiện chức năng!");
            balloonTip1.ShowBalloon(lvNhanVien);
        }

        private void Btn_Thoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        public void LamMoi()
        {
            txtMaNV.Text = "";
            Txt_HoTen.Text = "";
            dt_NgaySinh.IsEmpty = true;
            Cbm_ChucVu.SelectedIndex = -1;
            Txt_DiaChi.Text = "";
            Txt_DienThoai.Text = "";
            dt_NgayVL.IsEmpty = true;
            Txt_MucLuong.Text = "0";
            txtMaNV.Focus();
        }

        private void btnReset_Click(object sender, EventArgs e)
        {
            LamMoi();
            LayDanhSachNhanVien();
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnInDS_Click(object sender, EventArgs e)
        {
            frmReport_NhanVien frm = new frmReport_NhanVien();
            frm.ShowDialog();
        }
    }
}
